﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace TnFormLib
{
    public partial class TnFormStandard : UserControl
    {
        protected int bit = 0;
        protected Point p1;
        protected Point p2;
        protected int curWidth = 0;
        protected int curHight = 0;
        public TnFormStandard()
        {
            InitializeComponent();
        }

        protected void TnFormStandard_Load(object sender, EventArgs e)
        {
            this.ParentForm.FormBorderStyle = FormBorderStyle.None;
            this.Dock = DockStyle.Fill;
            this.ParentForm.TransparencyKey = System.Drawing.Color.FromArgb(121, 121, 121);
            this.ptbIcon.Image = this.ParentForm.Icon.ToBitmap();
            this.lblCaption.Text = this.ParentForm.Text;
        }

        protected void pnlCaptionBar_MouseDown(object sender, MouseEventArgs e)
        {
            bit = 1;
            p1 = this.ParentForm.Location;
            p2 = e.Location;
        }

        protected void pnlCaptionBar_MouseMove(object sender, MouseEventArgs e)
        {
            if (bit == 1)
            {
                this.ParentForm.Location = new Point(this.ParentForm.Location.X+e.Location.X-p2.X,this.ParentForm.Location.Y+e.Location.Y-p2.Y);
                //MessageBox.Show(this.ParentForm.Location.X.ToString());
            }
        }

        protected void pnlCaptionBar_MouseUp(object sender, MouseEventArgs e)
        {
            bit = 0;
            //MessageBox.Show(e.Location.X.ToString());
            
        }

        protected void pnlCaptionBar_Paint(object sender, PaintEventArgs e)
        {
            //this.SendToBack();
        }

        private void ptbIcon_MouseHover(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Hand;
        }

        private void ptbClose_Click(object sender, EventArgs e)
        {
            
            Application.ExitThread();
            Application.Exit();
        }

        private void ptbClose_MouseDown(object sender, MouseEventArgs e)
        {
            ptbClose.Image = global::TnFormLib.Properties.Resources.closedn;
        }

        private void ptbMini_MouseDown(object sender, MouseEventArgs e)
        {
            ptbMini.Image = global::TnFormLib.Properties.Resources.mindn;
        }

        private void ptbMini_Click(object sender, EventArgs e)
        {
            this.ParentForm.WindowState = FormWindowState.Minimized;
        }

        private void ptbHelp_MouseDown(object sender, MouseEventArgs e)
        {
            ptbHelp.Image = global::TnFormLib.Properties.Resources.helpdwn;
        }

        private void ptbIcon_MouseLeave(object sender, EventArgs e)
        {
            this.Cursor = Cursors.Arrow;
        }

        private void ptbClose_MouseUp(object sender, MouseEventArgs e)
        {
            ptbClose.Image = global::TnFormLib.Properties.Resources.closeup;
        }

        private void ptbMini_MouseUp(object sender, MouseEventArgs e)
        {
            ptbMini.Image = global::TnFormLib.Properties.Resources.minup;
        }

        private void ptbHelp_MouseUp(object sender, MouseEventArgs e)
        {
            ptbHelp.Image = global::TnFormLib.Properties.Resources.helpup;
        }

        private void panel8_MouseDown(object sender, MouseEventArgs e)
        {
            bit = 1;
            curWidth = this.ParentForm.Width;
            p1 = e.Location;
        }

        private void panel8_MouseUp(object sender, MouseEventArgs e)
        {
            bit = 0;
            
        }

        private void panel8_MouseMove(object sender, MouseEventArgs e)
        {

        }

        private void panel7_MouseDown(object sender, MouseEventArgs e)
        {

        }

        private void panel7_MouseUp(object sender, MouseEventArgs e)
        {

        }

        private void panel7_MouseMove(object sender, MouseEventArgs e)
        {

        }

    }
}
